package org.nightrunner.d3.service.impl;

import java.io.Serializable;
import java.util.List;

import org.nightrunner.d3.dao.IPrefixDao;
import org.nightrunner.d3.entity.Prefix;
import org.nightrunner.d3.model.DefaultPaginationInfo;
import org.nightrunner.d3.model.IPaginationInfo;
import org.nightrunner.d3.model.PaginationModel;
import org.nightrunner.d3.service.IPrefixService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * Prefix Service implementation
 * 
 * @author NigthRunner
 * @date 2012-7-26
 * @version 1.0
 */

@Service
public class PrefixService implements IPrefixService {

	@Autowired
	private IPrefixDao prefixDao;

	public IPrefixDao getPrefixDao() {
		return prefixDao;
	}

	public void setPrefixDao(IPrefixDao prefixDao) {
		this.prefixDao = prefixDao;
	}

	public Serializable addPrefix(Prefix prefix) {
		return prefixDao.save(prefix);
	}

	public Prefix getPrefix(String bureauId) {
		return prefixDao.get(bureauId);
	}

	public List<Prefix> getAllPrefix() {
		return prefixDao.list();
	}

	public void deletePrefix(Prefix prefix) {
		prefixDao.delete(prefix);
	}

	public PaginationModel<List<Prefix>> getPrefix() {
		IPaginationInfo paginationInfo = new DefaultPaginationInfo();
		paginationInfo.setCurrentPage(0);
		paginationInfo.setRowSize(10);
		return getPrefixs(paginationInfo);
	}

	public PaginationModel<List<Prefix>> getPrefixs(IPaginationInfo pagination) {
		return prefixDao.find(pagination);
	}

	public void updatePrefix(Prefix prefix) {
		prefixDao.merge(prefix);
	}
}
